<template>
	<!-- 查看赛果 -->
	<view class="page-content">
		<view class="index-body" v-if="datalist.remarks!=''">
			<rich-text class="con-text" :nodes='datalist.remarks' decode='true'></rich-text>
		</view>
		<!--无数据-->
		<empty v-else no-full type="noData"></empty>
	</view>
</template>

<script>
	import {
		getGameOverRemarks, //获取赛事详情富文本
	} from '@/common/api.js'
	export default {
		components: {
		},
		data() {
			return {
				datalist: {
					remarks: ''
				},
				game_id:'',
			}
		},
		onLoad(option){
			if(option.id){
				this.game_id = option.id;
			}
			this.getdata();
			// #ifdef MP-WEIXIN
			wx.showShareMenu({
					withShareTicket:true,
					//设置下方的Menus菜单，才能够让发送给朋友与分享到朋友圈两个按钮可以点击
					menus:["shareAppMessage","shareTimeline"]
				})
			//#endif
		},
		//发送给朋友
		onShareAppMessage(res) {
			// 此处的distSource为分享者的部分信息，需要传递给其他人
			let distSource = uni.getStorageSync('distSource');
			if (distSource) {
				return {
					title: '欢迎使用穿越小程序',
					type: 0,
					path: '/pages/index/match_detail?id=' + distSource,
					summary: "",
					imageUrl: ""
				}
			}
		},
		//分享到朋友圈
		onShareTimeline(res) {
			let distSource = uni.getStorageSync('distSource');
			if (distSource) {
				return {
					title: '欢迎使用穿越小程序',
					type: 0,
					query: 'id=' + distSource,
					summary: "",
					imageUrl: ""
				}
			}
		},
		methods: {
			getdata(){
				getGameOverRemarks({id:this.game_id}).then(res2=>{
					if (res2.code === 2000) {
						this.datalist.remarks = this.formatRichText(res2.data.data)
					}else{
						uni.showToast({
							title:res2.msg,
							icon:'none',
							duration:2000
						})
					}
				})
			},
			formatRichText(html) {
					let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
						match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
						match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
						match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
						return match;
					});
					newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
						match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
						return match;
					});
					newContent = newContent.replace(/<br[^>]*\/>/gi, '');
					newContent = newContent.replace(/\<img/gi,
						'<img style="max-width:100%;height:auto;display:inline-block;margin:10rpx auto;"');
					return newContent;
			},
		},
		onPullDownRefresh() {
			if (this.$refs.indexPage) {
				//this.$refs.indexPage.getData()
				console.log(1231)
			}

		}
	}
</script>

<style lang="scss">
	
	.page-content{
		// display: flex;
		// flex-direction: column;
		width: 100vw;
		height: 100%;
	}
	.index-header{
		height: 80rpx;
	}
	.index-body{
		margin: 30rpx;
		background-color: #f5f5f5;
		.con-text{
			width: 100%;
			display: flex;
			flex-direction: column;
			font-size: 28rpx;
			color: #666;
			line-height: 40rpx;
			image{
				width: 100%!important;
				max-width: 100%!important;
			}
		}
	}
</style>
